package com.sand.controller;

import com.sand.dto.worker.SelectProject;
import com.sand.entity.work.Project;
import com.sand.entity.work.Project_Worker;
import com.sand.result.ResponseResult;
import com.sand.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


//工程接口
@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    /**
     * 创建工程
     */
    @PostMapping("/add")
    private ResponseResult<Integer> add(@RequestBody Project project){
        Integer i =  projectService.add(project);
        return new ResponseResult<Integer>().ok(i);
    }

    /**
     * 查看该工程下的工人
     */
    @PostMapping("/getW")
    private ResponseResult<List<Project_Worker>> getw(@RequestBody Integer projectid){
        List<Project_Worker> list = projectService.getw(projectid);
        return new ResponseResult<List<Project_Worker>>().ok(list);
    }


    /**
     * 条件查看该用户的所有工程
     */
    @PostMapping("/list")
    private ResponseResult<List<Project>> getall(@RequestBody SelectProject selectProject){
        List<Project> list = projectService.getall(selectProject);
        return new ResponseResult<List<Project>>().ok(list);
    }

    /**
     * 工程完工
     */
    @PostMapping("/ok")
    private ResponseResult<Integer> ok(@RequestBody Integer projectid){
        Integer i = projectService.ok(projectid);
        return new ResponseResult<Integer>().ok(i);
    }



}
